package com.ruoyi.web.controller.dp;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dp.domain.DpFlightPlan;
import com.ruoyi.dp.service.IDpFlightPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(description="计划航班")
@RestController
@RequestMapping("/dp/flightPlan")
public class DpFlightPlanServiceController extends BaseController {

    @Autowired
    IDpFlightPlanService dpFlightPlanService;

    @ApiOperation("计划航班列表")
    @GetMapping("/list")
    public TableDataInfo list(DpFlightPlan dpFlightPlan){
        startPage();
        List<DpFlightPlan> list=dpFlightPlanService.selectDpFlightPlanList(dpFlightPlan);
        return getDataTable(list);
    }

    @ApiOperation("获取计划航班详细信息")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        DpFlightPlan dpFlightPlan = dpFlightPlanService.selectDpFlightPlanById(ID);
        return success (dpFlightPlan);
    }

    @ApiOperation("新增计划航班")
    @Log(title = "计划航班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DpFlightPlan dpFlightPlan) {
        return toAjax(dpFlightPlanService.insertDpFlightPlan(dpFlightPlan));
    }

    @ApiOperation(value = "修改计划航班")
    @Log(title = "计划航班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DpFlightPlan dpFlightPlan)
    {
        return toAjax(dpFlightPlanService.updateDpFlightPlan(dpFlightPlan));
    }


    /**
     * 删除计划航班
     */
    @ApiOperation(value = "删除计划航班")
    @Log(title = "计划航班", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        System.out.println("删除计划航班");
        System.out.println(IDs.toString());
        return toAjax(dpFlightPlanService.deleteDpFlightPlanByIds(IDs));
    }


    @Log(title = "计划航班", businessType = BusinessType.IMPORT)
    @ApiOperation("计划航班导入")
    @PostMapping(value = "/importData", consumes = "multipart/form-data")
    public AjaxResult importData(@ApiParam(name="file", value = "文件", required = true) MultipartFile file,
                                 @ApiParam(name="updateSupport", value = "是否支持更新数据（true:支持，false:不支持）", required = true)boolean updateSupport) throws Exception {
        ExcelUtil<DpFlightPlan> util = new ExcelUtil<DpFlightPlan>(DpFlightPlan.class);
        List<DpFlightPlan> dpFlightPlanList = util.importExcel(file.getInputStream());
        String message = dpFlightPlanService.importUser(dpFlightPlanList, updateSupport);
        return success(message);
    }
}
